# coding: utf-8
from PySide6.QtCore import Qt
from PySide6.QtGui import QColor
from PySide6.QtWidgets import QListWidget
from qfluentwidgets import BodyLabel, SmoothScrollDelegate, setFont

from common import StyleSheet


class TagListWidget(QListWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.scrollDelegate = SmoothScrollDelegate(self)

        self.tagLabel = BodyLabel(self)

        self.tagLabel.setTextColor(QColor(0, 0, 0, 200), QColor(255, 255, 255, 200))
        self.setFlow(QListWidget.Flow.LeftToRight)
        self.setSpacing(5)
        self.setFixedHeight(50)
        setFont(self, 14)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)

        StyleSheet.LIST_VIEW.apply(self)

    def setTag(self, tag: str):
        self.tagLabel.setText(tag)
        self.tagLabel.adjustSize()
        self.setViewportMargins(self.tagLabel.width() + 15, 0, 11, 0)

    def resizeEvent(self, event):
        super().resizeEvent(event)
        self.tagLabel.move(10, (self.height() - self.tagLabel.height()) // 2)

    # def enterEvent(self, event):
    #     self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
    #     super().enterEvent(event)
    #
    # def leaveEvent(self, event):
    #     self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
    #     super().leaveEvent(event)
